package leetcode.datastructure.stack;

import java.util.Stack;

public class Program232Office {

    Stack<Integer> first;
    Stack<Integer> second;

    public Program232Office() {
        first = new Stack<>();
        second = new Stack<>();
    }

    public void push(int x) {
        while(!first.empty()){
            second.push(first.pop());
        }
        second.push(x);
        while(!second.empty()){
            first.push(second.pop());
        }
    }

    public int pop() {
        return first.pop();
    }

    public int peek() {
        return first.peek();
    }

    public boolean empty() {
        return first.empty();
    }

    public static void main(String[] args) {
        Program232Office myQueue = new Program232Office();
        myQueue.push(1); // queue is: [1]
        myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
        System.out.println(myQueue.peek()); // return 1
        System.out.println(myQueue.pop()); // return 1, queue is [2]
        System.out.println(myQueue.empty()); // return false
    }
}
